package br.usp.pcs.basys2.engine;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.junit.Test;

import br.usp.pcs.basys2.SimulationInput;
import br.usp.pcs.basys2.info.FileActivityInfo;
import br.usp.pcs.basys2.info.FileInfo;
import br.usp.pcs.basys2.info.JobInfo;
import br.usp.pcs.basys2.info.PeripheralInfo;
import br.usp.pcs.basys2.info.ProcessInfo;
import br.usp.pcs.basys2.info.FileActivityInfo.Mode;
import br.usp.pcs.basys2.memory.Memory;
import br.usp.pcs.basys2.memory.MemoryManager;


public class EngineTestWithFileAcess {

	//@Test
	public void shouldRunProcess(){
		SimulationInput input = new SimulationInput();
		List<JobInfo> jobs = new ArrayList<JobInfo>();
		ProcessInfo topProcess = generateProcessInfo();
		Calendar instance = Calendar.getInstance();
		instance.setTimeInMillis(0);
		JobInfo jobInfo = new JobInfo(instance, topProcess );
		jobs.add(jobInfo);
		input.setJobs(jobs);
		Engine engine = Engine.getInstance();
		BasysSystem system = new BasysSystem(new MemoryManager(new Memory(10000)));
		
		List<PeripheralInfo> peripheralInfoList = new ArrayList<PeripheralInfo>();
		PeripheralInfo disk = new PeripheralInfo();
		disk.setAccessTime(5000);
		disk.setName("Disk");
		peripheralInfoList.add(disk);
		system.getPeripheralManager().setPeripherals(peripheralInfoList);
		
		
		List<FileInfo> fileInfoList = new ArrayList<FileInfo>();
		FileInfo fileInfo = new FileInfo();
		fileInfo.setName("filename.ext");
		fileInfoList.add(fileInfo);
		system.getFileManager().setFiles(fileInfoList );
		
		engine.setSystem(system);
		engine.load(jobs);
		engine.run();
	}


	private ProcessInfo generateProcessInfo() {
		ProcessInfo topProcess = new ProcessInfo();
		topProcess.setId(1L);
		topProcess.setCpuTotalTime(1000);
		topProcess.setSegmentSize(500);
		
		List<FileActivityInfo> fileActivities = new ArrayList<FileActivityInfo>();
		FileActivityInfo info = new FileActivityInfo();
		info.setFileName("filename.ext");
		info.setMode(Mode.READ);
		fileActivities.add(info);
		topProcess.setFileActivities(fileActivities);
		
		List<ProcessInfo> childProcesses = new ArrayList<ProcessInfo>();
		
		ProcessInfo childProcess = new ProcessInfo();
		childProcess.setId(2L);
		childProcess.setCpuTotalTime(1000);
		childProcess.setSegmentSize(300);
		
		childProcesses.add(childProcess);
		
		topProcess.setChildProcesses(childProcesses );
		return topProcess;
	}
	
}
